387B - George and Round - CodeForces Solution


brute force greedy two pointers *1200

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define AYAALI ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define FOR(i, a, b) for(int i = int(a); i < int(b); i++)
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define ll long long
#define pb(x) push_back(x)
#define MP(x, y) make_pair(x,y)
#define fi first
#define se second
#define endl '\n'
#define all(v) v.begin(), v.end()
const double EPS = 1e-9;
const ll N=1e5+1;
//---------------------------------------------
void files(){
    freopen("highcard.in", "r", stdin);
    freopen("highcard.out", "w", stdout);
}

void solve(){
    ll n,m;
    cin>>n>>m;
    multiset<ll>v2;
    vector<ll>v1;
    for(int i=0;i<n;i++){
        ll x;cin>>x;
        v1.pb(x);
    }
    for(int i=0;i<m;i++){
        ll y;cin>>y;
        v2.insert(y);
    }
    ll cnt  = 0;
    for(int i=0;i<n;i++){
        if(v2.find(v1[i])!=v2.end() ){
           v2.erase(v2.find(v1[i]));
        }else if(v2.upper_bound(v1[i])!=v2.end()){
            v2.erase(v2.upper_bound(v1[i]));
        }else{
            cnt++;
        }
    }
    cout<<cnt;



}
int main() {
    ll t= 1;
    //cin>>t;
    //files();
    while(t--){
        solve();
    }


    return 0;
}


	  	 	 	   			 			  			  	   		


Comments

Submit
0 Comments
More Questions

740A - Alyona and copybooks
1491A - K-th Largest Value
922B - Magic Forest
922D - Robot Vacuum Cleaner
408B - Garland
1391A - Suborrays
1700C - Helping the Nature
982A - Row
877A - Alex and broken contest
919D - Substring
362B - Petya and Staircases
1535C - Unstable String
1738F - Connectivity Addicts
1342B - Binary Period
1551C - Interesting Story
794B - Cutting Carrot
534B - Covered Path
1278C - Berry Jam
1203A - Circle of Students
1740B - Jumbo Extra Cheese 2
1740A - Factorise N+M
49B - Sum
23A - You're Given a String
1105C - Ayoub and Lost Array
1624E - Masha-forgetful
998B - Cutting
250A - Paper Work
1740C - Bricks and Bags
1130A - Be Positive
465A - inc ARG